package org.mspring.mlog.web.module.web.widget;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.mspring.mlog.entity.Catalog;
import org.mspring.mlog.service.CatalogService;
import org.mspring.platform.web.freemarker.widget.stereotype.Widget;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 *
 * @author Gao Youbo
 * @since 2013年9月23日
 */
@Widget
@RequestMapping("/widget/catalog")
public class Widget_CatalogWidget extends Widget_AbstractWidget {

    @Autowired
    private CatalogService catalogService;

    /**
     * 分类列表
     *
     * @param tpl
     * @param request
     * @param response
     * @param model
     * @return
     */
    @RequestMapping("/list")
    public String list(@RequestParam(required = false, defaultValue = "/widget/catalog/list") String tpl, HttpServletRequest request, HttpServletResponse response, Model model) {
        List<Catalog> catalogs = catalogService.listAll();
        model.addAttribute("catalogs", catalogs);
        return "skin:" + tpl;
    }
}
